﻿Imports ccapps.persistent.Promotions
Public Class WebForm2
    Inherits [lib].BasePage
    Dim e As DataGridCommandEventArgs

    Dim dogru As Integer = 0


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        '   PromotionInfoTable.Visible = False
        '  PromotionGridTable.Visible = False
        Me.PageTitle = "Müşteri Promosyon Görüntüleme"
        If Session("user") = "" Or Session("user") Is Nothing Then
            ' Response.Redirect("../../login.aspx")
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If

    End Sub

    Protected Sub btnCheckMsisdn_Click(sender As Object, e As EventArgs) Handles btnCheckMsisdn.Click
        Try

        'PromotionGridTable.Visible = True
        TB_Custcode.Text = ""
        lblAbone.Text = ""
        lblCustomerID.Text = ""
        ErrorMessage.Text = ""
        DG_CustPromotionDetayList.DataSource = Nothing
        DG_CustPromotionDetayList.DataBind()
        DG_CustPromotionList.DataSource = Nothing
        DG_CustPromotionListDeactive.DataSource = Nothing
            DG_CustPromotionListDeactive.DataBind()
            PromosyonGrid.Visible = False
        MSISDNSearch()
        Catch ex As Exception
            ErrorMessage.Text = "İşlemde Hata oluşmuştur.Tekrar deneyiniz"
            'ErrorMessage.Text = ex.ToString()
        End Try

    End Sub

    Protected Sub btnCheckCustCode_Click(sender As Object, e As EventArgs) Handles btnCheckCustCode.Click

        ' PromotionGridTable.Visible = True
        Try

        
        TB_MSISDN.Text = ""
        lblAbone.Text = ""
        lblCustomerID.Text = ""
        ErrorMessage.Text = ""
        DG_CustPromotionDetayList.DataSource = Nothing
        DG_CustPromotionDetayList.DataBind()
        DG_CustPromotionList.DataSource = Nothing
        DG_CustPromotionListDeactive.DataSource = Nothing
            DG_CustPromotionListDeactive.DataBind()
            PromosyonGrid.Visible = False
            CustcodeSearch()

        Catch ex As Exception
            ErrorMessage.Text = "İşlemde Hata oluşmuştur.Tekrar deneyiniz"
        End Try
    End Sub


    Private Sub CustcodeSearch()
        ErrorMessage.Text = ""
        Dim pin_Custcode As String = TB_Custcode.Text
        Dim dt As DataTable = GetCustInfoFromCustcode(pin_Custcode)
        If dt.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt.Rows
                If dr2("cstype").ToString() = "C" Then
                    lblAbone.Text = dr2("CCNAME").ToString() + "," + dr2("ccfname").ToString() + "," + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                Else
                    lblAbone.Text = dr2("ccfname").ToString() + "," + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                End If

                'lblAbone.Text = dr2("ccfname").ToString() + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                lblCustomerID.Text = dr2("CUSTOMER_ID").ToString()
                Button1.Enabled = True
            Next
        Else
            Button1.Enabled = False
            ErrorMessage.Text = "Girmiş olduğunuz Custcode'a ait veri bulunamamıştır."
        End If
    End Sub

    Private Sub MSISDNSearch()
        ErrorMessage.Text = ""
        Dim pin_MSISDN As String = TB_MSISDN.Text.Trim()
        Dim dt As DataTable = GetCustInfoFromMSISDN(pin_MSISDN)
        If dt.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt.Rows
                If dr2("cstype").ToString() = "C" Then
                    lblAbone.Text = dr2("CCNAME").ToString() + "," + dr2("ccfname").ToString() + "," + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                Else
                    lblAbone.Text = dr2("ccfname").ToString() + "," + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                End If

                'lblAbone.Text = dr2("ccfname").ToString() + dr2("cclname").ToString() + "," + dr2("CCCITY").ToString()
                lblCustomerID.Text = dr2("CUSTOMER_ID").ToString()
                hiddenCOID.Text = dr2("CO_ID").ToString()
                Button1.Enabled = True
            Next
        Else
            Button1.Enabled = False
            ErrorMessage.Text = "Girmiş olduğunuz MSISDN'e ait veri bulunamamıştır."
        End If
    End Sub

    Private Sub GetDisplayCustomerPromotion(ByVal currentPageIndex As Integer)

        Dim pin_customer_id As Integer = Convert.ToInt32(lblCustomerID.Text)
        Dim dt As DataTable = GetCustomerPromotionList(pin_customer_id)
        Me.DG_CustPromotionList.CurrentPageIndex = currentPageIndex
        DG_CustPromotionList.DataSource = dt
        DG_CustPromotionList.DataBind()
    End Sub

    Private Sub GetDisplayCustomerPromotionDeactive(ByVal currentPageIndex As Integer)

        Dim pin_customer_id As Integer = Convert.ToInt32(lblCustomerID.Text)
        Dim dt As DataTable = GetCustomerPromotionListDeactive(pin_customer_id)
        Me.DG_CustPromotionListDeactive.CurrentPageIndex = currentPageIndex
        DG_CustPromotionListDeactive.DataSource = dt
        DG_CustPromotionListDeactive.DataBind()
    End Sub

    Private Sub GetDisplaySIMHistoryWithMSISDN()

        Dim pin_customer_id As Integer = Convert.ToInt32(lblCustomerID.Text)
        Dim pin_CO_ID As Integer = Convert.ToInt32(hiddenCOID.Text)
        Dim dt As DataTable = DisplayOCCHistoryWithCOID(pin_customer_id, pin_CO_ID)
    End Sub



    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try

            Dim currentPageIndex = Me.DG_CustPromotionList.CurrentPageIndex
            Dim currentPageIndex2 = Me.DG_CustPromotionListDeactive.CurrentPageIndex
            GetDisplayCustomerPromotion(currentPageIndex)
            GetDisplayCustomerPromotionDeactive(currentPageIndex2)
            baslik.Visible = True
            baslik2.Visible = True
            PromosyonGrid.Visible = True

        Catch ex As Exception
            ErrorMessage.Text = "İşlemde Hata oluşmuştur.Tekrar deneyiniz"
        End Try
    End Sub

    Protected Sub deneme(source As Object, e As DataGridCommandEventArgs) Handles DG_CustPromotionList.ItemCommand
        'boyama()
        '  For Each item As DataGridItem In Me.DG_CustPromotionList.Items
        'item.Cells(1).BackColor = Color.DarkSlateGray
        'Next
        If e.CommandName = "view" Then
            'e.Item.Parent("testit") = e.Ite
            Dim dt As DataTable = GetCustomerPromotionDetail(e.Item.Cells(1).Text, e.Item.Cells(2).Text, e.Item.Cells(5).Text)
            DG_CustPromotionDetayList.DataSource = dt
            DG_CustPromotionDetayList.Visible = True
            DG_CustPromotionDetayList.DataBind()
            e.Item.BackColor = Color.Yellow
        End If
    End Sub

   
    Protected Sub view(source As Object, e As DataGridCommandEventArgs) Handles DG_CustPromotionListDeactive.ItemCommand
        If e.CommandName = "view" Then
            'e.Item.Parent("testit") = e.Ite
            Dim dt As DataTable = GetCustomerPromotionDetail(e.Item.Cells(1).Text, e.Item.Cells(2).Text, e.Item.Cells(5).Text)
            DG_CustPromotionDetayList.DataSource = dt
            DG_CustPromotionDetayList.Visible = True
            DG_CustPromotionDetayList.DataBind()
            e.Item.BackColor = Color.Yellow
        End If
    End Sub


   

   
End Class